//配置全局根路径
axios.defaults.baseURL = 'http://big-event-api-t.itheima.net'

//todo 拦截器
// 请求拦截器
axios.interceptors.request.use(config => {
    //!判断网址是否是  /my  的网址请求
    if (config.url.includes('/my')) {
        config.headers.Authorization = localStorage.getItem('token')
    }
    return config;
}, error => {
    // Do something with request error
    return Promise.reject(error);
});

//响应拦截器
axios.interceptors.response.use(response => {
    //!  判断身份信息是否验证成功
    if (response.data.status === 1 && response.data.message === '身份认证失败！') {
        location.href = '/login.html'
    }
    return response;
}, error => {
    // Do something with response error
    return Promise.reject(error);
});